#X ?

import commands, os, string
from Tkinter import *

X_PATH = "/usr/bin/Xorg"

def X_present():
    """
    teste la presence de X sur la machine
    """
    output = commands.getoutput("ps -e |grep X")
    proginfo = string.split(output)
    if (len(proginfo) >= 4) and (proginfo[3] == 'Xorg' or proginfo[3] == "X"):
        return True
    else:
        return False

def makeentry(parent, caption, width=None, **options):
    Label(parent, text=caption).pack(side=LEFT)
    entry = Entry(parent, **options)
    if width:
        entry.config(width=width)
        entry.pack(side=LEFT)
    return entry


def X_promp(prompt):
    """
    pop une fenetre
    """
    master = Tk()

    h = 100
    w = 200
    ws = master.winfo_screenwidth()
    hs = master.winfo_screenheight()
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    master.geometry('%dx%d+%d+%d' % (w, h, x, y))

    def callback():
        master.quit()

    t = Label(master, text="", fg="yellow")
    t.pack()

    e = Entry(master, width=20)
    e.pack()

    txt = Label(master, text=prompt, fg="yellow")
    txt.pack()

    b = Button(master, text="OK", width=10, command=callback)
    b.pack()

    mainloop()
    return (e.get())


if __name__ == '__main__':    
    if X_present(): 
        print "X is running"
        print X_promp("Please set a volume size")
    else: 
        print "X is not running"

